package com.zjy.software.day15;

public class DrawThread extends Thread {
    private  String name;
    private Account account;
    DrawThread(Account account,String name) {
        this.account = account;
        this.name=name;
    }
    @Override
    public void run() {

       while (true) {
           if (drawMoney()) break;
       }
    }

    private synchronized boolean   drawMoney() {
          if(account.getCount() > 0) {
             account.setCount(account.getCount() - 100);
              System.out.println(name+"  取走100元,余额为:"+account.getCount());
              try {
                  Thread.sleep(500);
              } catch (InterruptedException e) {
                  throw new RuntimeException(e);
              }
          } else {
              return true;
          }

        return false;
    }
}